package cn.b.sky.form.form.builder.impl;

import cn.b.sky.form.form.builder.BaseElementBuilder;
import cn.b.sky.form.model.BusinessField;
import cn.b.sky.form.model.ScreenField;
import org.apache.commons.lang3.StringUtils;

public class DateTimeBuilder extends BaseElementBuilder {

  @Override
  public String buildHtmlElement(ScreenField sf) {
    BusinessField field = sf.getBf();
    StringBuilder sb = new StringBuilder();
    sb.append("<input type=\"text\" readonly class=\"");
    if (sf.getReadonlyFlag() != 1) {
      sb.append("date ");
      //输入框检验
      String validation = this.getValidationAttribute(field);
      if (!StringUtils.isBlank(validation)) {
        sb.append(validation);
      }
    }
    sb.append("\"");
    sb.append(" id=\"").append(field.getFieldLabel()).append("\"");
    if (!StringUtils.isBlank(field.getDbField()) && sf.getReadonlyFlag() != 1) {
      sb.append("name=\"").append(field.getDbField()).append("\"");
    }
    sb.append(" value=\"").append(field.getDefaultValue()).append("\"");
    sb.append("dateFmt=\"yyyy-MM-dd HH:mm:ss\" />");
    if (sf.getReadonlyFlag() != 1) {
      sb.append("<a class=\"inputDateButton\" href=\"javascript:;\">选择</a>");
    }
    return sb.toString();
  }

}
